/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#ifndef __LIBLINUX_SCHED_H__

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/wake_q.h>
#include <linux/kern_levels.h>
#include <linux/blkdev.h>
#include <linux/taskstats.h>
#include <linux/delayacct.h>
#include <linux/kernel_stat.h>
#include "../../kernel/workqueue_internal.h"
#include "../../io_uring/io-wq.h"

#ifdef CONFIG_LIBLINUX

static inline void sched_update_worker(struct task_struct *tsk)
{
	if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
		if (tsk->flags & PF_WQ_WORKER)
			wq_worker_running(tsk);
		else
			io_wq_worker_running(tsk);
	}
}

static inline void sched_submit_work(struct task_struct *tsk)
{
	unsigned int task_flags;

	if (tsk->state == TASK_RUNNING)
		return;

	task_flags = tsk->flags;

	if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
		preempt_disable();
		if (tsk->flags & PF_WQ_WORKER)
			wq_worker_sleeping(tsk);
		else
			io_wq_worker_sleeping(tsk);
		preempt_enable_no_resched();
	}

	if (tsk_is_pi_blocked(tsk))
		return;

	if (blk_needs_flush_plug(tsk))
		blk_schedule_flush_plug(tsk);
}

#endif /* CONFIG_LIBLINUX */
#endif /* __LIBLINUX_SCHED_H__ */
